package com.GlobalPaint.app.ui.Laborer;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.utils.MyViewPager;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.finalteam.toolsfinal.adapter.FragmentAdapter;

import static com.GlobalPaint.app.R.id.iv_goback;


public class LaborerFragment extends Fragment {
    @BindView(iv_goback)
    ImageView ivGoback;
    @BindView(R.id.tv_common_center)
    TextView tvCommonCenter;
    @BindView(R.id.tv_job_wanted)
    TextView tvJobWanted;
    @BindView(R.id.vw_job_wanted)
    View vwJobWanted;
    @BindView(R.id.ll_job_wanted)
    LinearLayout llJobWanted;
    @BindView(R.id.tv_recruit)
    TextView tvRecruit;
    @BindView(R.id.vw_recruit)
    View vwRecruit;
    @BindView(R.id.ll_recruit)
    LinearLayout llRecruit;
    @BindView(R.id.tv_temporary_work)
    TextView tvTemporaryWork;
    @BindView(R.id.vw_temporary_work)
    View vwTemporaryWork;
    @BindView(R.id.ll_temporary_work)
    LinearLayout llTemporaryWork;
    Unbinder unbinder;
    @BindView(R.id.view_pager)
    MyViewPager viewPager;
    private JobWantedFragment jobWantedFragment;
    private RecruitFragment recruitFragment;
    private TemporaryWorkFragment temporaryWorkFragment;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_laborer, container, false);

        unbinder = ButterKnife.bind(this, view);
        initView(view);
        //初始化TabLayout的title数据集
        List<String> titles = new ArrayList<>();
        titles.add("");
        titles.add("");
        titles.add("");
        jobWantedFragment=new JobWantedFragment();
        recruitFragment=new RecruitFragment();
        temporaryWorkFragment=new TemporaryWorkFragment();
        //初始化ViewPager的数据集
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(jobWantedFragment);
        fragments.add(recruitFragment);
        fragments.add(temporaryWorkFragment);
        //创建ViewPager的adapter
        FragmentAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragments, titles);
        viewPager.setAdapter(adapter);
        return view;
    }

    private void initView(View v) {
        ivGoback.setVisibility(View.GONE);
        tvCommonCenter.setText("用工");
    }

    @OnClick({iv_goback, R.id.ll_job_wanted, R.id.ll_recruit, R.id.ll_temporary_work})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_job_wanted:
                tvJobWanted.setTextColor(Color.rgb(123,211,255));
                tvRecruit.setTextColor(Color.rgb(104,104,104));
                tvTemporaryWork.setTextColor(Color.rgb(104,104,104));
                vwJobWanted.setVisibility(View.VISIBLE);
                vwRecruit.setVisibility(View.GONE);
                vwTemporaryWork.setVisibility(View.GONE);
                viewPager.setCurrentItem(0);
                break;
            case R.id.ll_recruit:
                tvJobWanted.setTextColor(Color.rgb(104,104,104));
                tvRecruit.setTextColor(Color.rgb(123,211,255));
                tvTemporaryWork.setTextColor(Color.rgb(104,104,104));
                vwJobWanted.setVisibility(View.GONE);
                vwRecruit.setVisibility(View.VISIBLE);
                vwTemporaryWork.setVisibility(View.GONE);
                viewPager.setCurrentItem(1);
                break;
            case R.id.ll_temporary_work:
                tvJobWanted.setTextColor(Color.rgb(104,104,104));
                tvRecruit.setTextColor(Color.rgb(104,104,104));
                tvTemporaryWork.setTextColor(Color.rgb(123,211,255));
                vwJobWanted.setVisibility(View.GONE);
                vwRecruit.setVisibility(View.GONE);
                vwTemporaryWork.setVisibility(View.VISIBLE);
                viewPager.setCurrentItem(2);
                break;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
